﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO.Ports;
using System.Windows.Forms;
using CoreShop.Library;
using System.Data;
using System.Drawing.Printing;
using CoreShop.App;
using System.Runtime.InteropServices;
using System.Data.OleDb;

namespace CoreShop
{
   /// <summary> 
    /// 客显  
    /// </summary>  
    public class VTopLed8c
    {
        [DllImport("TPD108DLL.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern Boolean OpenComm(string sComm, int iBaudRate);

        [DllImport("TPD108DLL.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern void CloseComm();

        [DllImport("TPD108DLL.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int LED_Init();

        [DllImport("TPD108DLL.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int LED_ClearScreen();

        [DllImport("TPD108DLL.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int LED_SetBaudrate(int baudrate);

        [DllImport("TPD108DLL.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int LED_Display(string sText, int iStatus);


        public static Boolean isOpened = false;

        const int FILE_DOWN_BOOTLOGO = 1;
        const int FILE_DOWN_BACKGROUND = 2;
        const int FILE_DOWN_CENTERLOGO = 3;

        const int ERR_SC_SUCCESS = 0;
        const int ERR_SC_NOTACTIVE = 1;
        const int ERR_SC_BUSY = 2;
        const int ERR_SC_TIMEOUT = 3;
        const int ERR_DS_CHECKERR = 4;
        const int ERR_DS_FILENOTEEXIST = 5;
        const int ERR_DS_WRONGFILENO = 6;
        const int ERR_DS_DOWNFAILED = 7;
        const int ERR_DS_ISEMPTY = 8;
        const int ERR_DS_FAILED = 9;
        const int ERR_DS_BAD_FORMAT = 10;

        string[] Baudrates = new string[]
        {
            "2400", "4800", "9600"
        };


        public static void OpenPort()
        {
            try
            {
                var portName = CommFunc.ConvertStrValue(IniFiles.ReadIniData("CustShow", "LedPort"));
                var baudrate = int.Parse(CommFunc.ConvertStrValue(IniFiles.ReadIniData("CustShow", "LedBaud")));
                if (OpenComm(portName, baudrate))
                {
                    isOpened = true;
                }
                else
                {
                    MessageBox.Show("Error opening serial port");
                }

            }
            catch (Exception ex)
            {
                //MessageBox.Show("顾显出错：" + ex.Message);
            }

        }

        /// <summary>
        /// 顾显的调用
        /// </summary>
        /// <param name="strMoney"></param>
        /// <param name="iShowType"></param>
        public static void DisplayData(string strMoney, int iShowType)
        {
            LED_Display(strMoney, iShowType);
        }

    }

}

